#include <modules\graphics\model.h>

namespace DelGE
{
	namespace Modules
	{
		namespace Graphics
		{
			Model::Model()
			{
				this->pTexture = NULL;
				this->pMesh = NULL;
			}

			Model::Model(Model *pModel)
			{
				this->pTexture = pModel->pTexture;
				this->pMesh = new Mesh(pModel->GetMesh());
			}

			Model::~Model()
			{
				this->pTexture = NULL;
				if (this->pMesh != NULL)
				{
					delete this->pMesh; 
					this->pMesh = NULL;
				}
			}

			Model* Model::CreateBlank()
			{
				Model* pModel = new Model();
				Mesh* pMesh = new Mesh();

				pModel->SetMesh(pMesh);

				return pModel;
			}

			Model* Model::CreateCube(float fWidth, float fHeight, float fDepth, float fXOffset, float fYOffset, float fZOffset)
			{
				Model* pModel = new Model();
				Mesh* pMesh = Mesh::CreateCube(fWidth, fHeight, fDepth, fXOffset, fYOffset, fZOffset);

				pModel->SetMesh(pMesh);

				return pModel;
			}
			
			Model* Model::CreatePlane(float fWidth, float fDepth, float fXOffset, float fZOffset)
			{
				Model* pModel = new Model();
				Mesh* pMesh = Mesh::CreatePlane(fWidth, fDepth, fXOffset, fZOffset);

				pModel->SetMesh(pMesh);

				return pModel;
			}

			void Model::SetTexture(Texture* pTexture)
			{
				this->pTexture = pTexture;
			}

			Texture* Model::GetTexture()
			{
				return this->pTexture;
			}

			void Model::SetMesh(Mesh* pMesh)
			{
				if (this->pMesh != NULL)
				{
					delete this->pMesh; 
					this->pMesh = NULL;
				}
				this->pMesh = pMesh;
			}

			Mesh* Model::GetMesh()
			{
				return this->pMesh;
			}
		}	
	}
}